a = int(input())
if a > 9999 or a < 1000:
    print('0')
    exit()
c = a // 1000
C2 = a // 100 % 10
C3 = a // 10 % 10
C4 = a % 10
minN = 0
b = [c, C2, C3, C4, c * 10 + C2, c * 100 + C2 * 10 + C3,a, C2 * 10 + C3,C2 * 100 + C3 * 10 + C4, C3 * 10 + C4]
for i in range(len(b)):
    k = 0
    for j in range(2, b[i] // 2 + 1):
        if b[i] % j == 0:
            k = k+1
    if k <= 0:
        if minN < b[i]:
            if b[i] != 1:
                minN = b[i]
print(minN)
